using System;
using System.Drawing;
using System.Collections.Generic;
using System.Text;

using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using TTDotNet.Engine.ThreeDEngine;

namespace TTDotNet.Engine.GUI
{
    public class GameButton : Control
    {
        private GameTexture _bgDown;
        private GameTexture _currentBg;
        private GameTexture _bgDisabled;

        public GameButton(RectangleF screenRect, string text, float fontSize, 
                            Color textColor, string fontName, GameTexture bgUp, GameTexture bgDown)
        {
            _size = screenRect;
            _size.Width = bgUp.Texture.GetLevelDescription(0).Width;
            _size.Height = bgUp.Texture.GetLevelDescription(0).Height;
            _text = text;
            _fontSize = fontSize;
            _fontColor = textColor;
            _fontName = fontName;
            textureUp = bgUp;
            _bgDown = bgDown;
            _currentBg = bgUp;
            _position = new PointF(screenRect.X, screenRect.Y);

            _bgDisabled = Game.textureCacher.LoadTexture("artwork/colours/red.jpg");

            _textRect = screenRect;
            
            //_text = "WOOOOOOOO";
            //_fontSize = 36;

            System.Drawing.Font systemFont = new System.Drawing.Font(fontName, fontSize);
            //_font = new Microsoft.DirectX.Direct3D.Font(Game.device, systemFont);

            SetSize(screenRect.Width, screenRect.Height);
        }

        public override void Render(PointF location)
        {
            //_textRect.Width = 300;
            
            if (_controlState == ControlState.Down) { _currentBg = _bgDown; }
            else if (_controlState == ControlState.Disabled) { _currentBg = _bgDisabled; }
            else { _currentBg = textureUp; }

            Game.guiSprite.Transform = spriteTransform;
            Game.guiSprite.Draw(_currentBg.Texture, Rectangle.Empty, Vector3.Empty, Vector3.Add(_renderPosition, new Vector3(location.X / WidthScale, location.Y / HeightScale, 0)), Color.White);

            if (!_text.Equals(string.Empty))
            {
                Game.guiSprite.Transform = Matrix.Identity;
                Game.arial14.DrawText(Game.guiSprite, _text, new Rectangle((int)(_textRect.X + location.X), (int)(_textRect.Y + location.Y), (int)_textRect.Width, (int)_textRect.Height), textFormat, _fontColor);
                Game.guiSprite.Transform = spriteTransform;
            }
        }

    }
}
